﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Odyssey.Controls;
using System.Diagnostics;

namespace OdcDemo
{
    public partial class JumpListPage : AnimationPhoneApplicationPage
    {
        // Constructor
        public JumpListPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            App.Reset();
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        // Handle selection changed on ListBox
        private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // If selected index is -1 (no selection) do nothing
            if (MainListBox.SelectedIndex == -1)
                return;

            int index = App.ViewModel.Items.IndexOf(MainListBox.SelectedItem as ItemViewModel);
            if (index >= 0)
            {
                
                NavigationService.Navigate(new Uri("/Pages/SwingPage.xaml?selectedItem=" + index, UriKind.Relative));

            }
            // Reset selected index to -1 (no selection)
            MainListBox.SelectedIndex = -1;
        }

        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            //turnstile.ListBox = MainListBox;
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }
        }

        private void OnScrollingChanged(object sender, Odyssey.Classes.ScrollingEventArgs e)
        {
     //       this.MainListBox.Background = e.IsScrolling ? new SolidColorBrush(Color.FromArgb(128, 0, 0, 255)) : new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
        }

    }
}